//AccountBaseApi.java
package com.lqjava.flowable.serverapp.app.api;

import com.lqjava.flowable.beans.result.ListResultBean;
import com.lqjava.flowable.beans.result.PageResultBean;
import com.lqjava.flowable.beans.result.ResultBean;
import com.lqjava.flowable.beans.utils.ParamsHelper;
import com.lqjava.flowable.beans.entity.request.IDRequest;
import com.lqjava.flowable.beans.entity.request.AccountBaseOptionRequest;
import com.lqjava.flowable.beans.entity.request.AccountBaseQuesrRequest;
import com.lqjava.flowable.beans.entity.response.AccountBaseViewResponse;
import com.lqjava.flowable.serverapp.app.service.AccountBaseService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/account/base")
public class AccountBaseApi {

    @Autowired
    private AccountBaseService service;

    //通过id获取视图对象
    @RequestMapping(value = {"/get","/getView"},method = RequestMethod.POST)
    public ResultBean<AccountBaseViewResponse> getView(@RequestBody IDRequest request){
        ParamsHelper.requiredValidator(request);
        ResultBean<AccountBaseViewResponse> res = new ResultBean<>();
        res.initTrue(service.getView(request));
        return res;
    }

    //通过查询对象获取试图集合
    @RequestMapping(value = {"/list","/listView"},method = RequestMethod.POST)
    public ListResultBean<AccountBaseViewResponse> listView(@RequestBody AccountBaseQuesrRequest request){
        ListResultBean<AccountBaseViewResponse> res = new ListResultBean<>();
        res.initTrue(service.listView(request));
        return res;
    }

    //通过查询对象获取试图分页集合
    @RequestMapping(value = {"/page","/pageView"},method = RequestMethod.POST)
    public PageResultBean<AccountBaseViewResponse> pageView(@RequestBody AccountBaseQuesrRequest request){
        PageResultBean<AccountBaseViewResponse> res = new PageResultBean<>();
        res.initTrue(service.pageView(request));
        return res;
    }


    //插入接口
    @RequestMapping(value = "/insert",method = RequestMethod.POST)
    public ResultBean<Long> insert(@RequestBody AccountBaseOptionRequest request){
        ResultBean<Long> res = new ResultBean<>();
        res.initTrue(service.insert(request));
        return res;
    }

    //修改接口
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public ResultBean<Long> update(@RequestBody AccountBaseOptionRequest request){
        ParamsHelper.requiredValidator(request,"id");
        ResultBean<Long> res = new ResultBean<>();
        res.initTrue(service.update(request));
        return res;
    }

    //保存接口 自动判断插入或者修改
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    public ResultBean<Long> save(@RequestBody AccountBaseOptionRequest request){
        ResultBean<Long> res = new ResultBean<>();
        res.initTrue(service.save(request));
        return res;
    }

    //删除接口
    @RequestMapping(value = "/del",method = RequestMethod.POST)
    public ResultBean<Long> del(@RequestBody IDRequest request){
        ParamsHelper.requiredValidator(request);
        ResultBean<Long> res = new ResultBean<>();
        res.initTrue(service.del(request));
        return res;
    }

}

